package com.example.apple.ddhr_new.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.activity.bean.UserBean;

import com.example.apple.ddhr_new.App;


import com.google.gson.Gson;


import java.util.ArrayList;
import java.util.List;

import static android.content.Context.MODE_PRIVATE;

public class CacheUtil {


    public  final  static  String USER_KEY="USER_KEY";
    public static  void  setAccount(UserBean userBean, Context context){
        SharedPreferences sp = context.getSharedPreferences("ddhr", MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        if(userBean==null){

            editor.remove(USER_KEY);
            editor.commit();
        }else {
            Gson gson = new Gson();



            editor.putString(USER_KEY, gson.toJson(userBean));

            editor.commit();
        }


    }


    public  static UserBean getAccount(Context context){
        SharedPreferences sp = context.getSharedPreferences("ddhr", MODE_PRIVATE);

        String data = sp.getString(USER_KEY,null);
        if(null==data){

            return null;
        }
        Gson gson = new Gson();


        UserBean userBean = gson.fromJson(data,UserBean.class);

        return  userBean;

    }






}
